<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>掌上工单</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../css/mui.min.css">
		<style type="text/css">
			.mui-bar{
				background-color: rgba(0,153,204,.9);
			}
			.mui-icon{
				color: #FFFFFF;
			}
		</style>	
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			
			
			<a id="search" class="mui-icon mui-icon-search mui-pull-right"></a>
			<h1 class="mui-title" style="color: #FFFFFF;" id='mui-title'>任务大厅</h1>
		</header>
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/md5.js" ></script>
		<script type="text/javascript" src="../js/uuid.js" ></script>
		<script type="text/javascript" src="../js/utils.js" ></script>
		<script src="../js/update.js"></script>
		<script>
			var titles = [];
				titles["home"] = '任务大厅';
				titles["emc"] = '客服工单';
				titles["notice"] = '通知公告';
				titles["setting"] = '系统设置';
				titles['tips'] = '通知设置' ;
				titles['about'] = '关于' ;
			var	main = null,
				waiting = null ;
			var showMenu = false;
			mui.init({
				swipeBack: false,
				statusBarBackground: '#f7f7f7',
				gestureConfig: {
					doubletap: true
				},
				subpages: [{
					id: 'emc-sub-home',
					url: 'sub-home.html',
					styles: {
						top: '45px',
						bottom: 0,
						bounce: 'vertical'
					}
				}]
			});
			mui.plusReady(function() {
				
				document.getElementById("search").addEventListener("tap",function(){
					mui.openWindow({
						url:'task-search.html',
						id:'emc-task-search',
						show: {
							aniShow: "pop-in"
						}
					});
				});
				
				
				plus.navigator.closeSplashscreen();
				plus.navigator.setFullscreen(false);
				waiting = plus.nativeUI.showWaiting() ;
				
				//监听网络变化事件
				document.addEventListener("netchange", function () {
				  var networkinfo = plus.networkinfo.getCurrentType() ;
				  if (plus.networkinfo.CONNECTION_NONE == networkinfo || plus.networkinfo.CONNECTION_UNKNOW == networkinfo) {
				    mui.toast("当前暂无网络连接，请打开数据服务!", "提示");
				  }else{
				  	/** 再次联网立即同步client数据*/
				  	xhz.syncClient();
				  }
				}, false);
			    
				//仅支持竖屏显示
				plus.screen.lockOrientation("portrait-primary");
				main = plus.webview.currentWebview();
				//处理侧滑导航，为了避免和子页面初始化等竞争资源，延迟加载侧滑页面；
				
				 //敲击顶部导航，内容区回到顶部
				document.querySelector('header').addEventListener('doubletap', function() {
					main.children()[0].evalJS('mui.scrollTo(0, 100)');
				});
				 //侧滑菜单触发关闭菜单命令
				
				//关闭加载画面
				window.addEventListener("wait:close", closeWaiting);
				
				window.addEventListener("title:set", setTitle);
			
				var backgroundTime = 0;
		        // 监听从前台切换到后台事件
			    document.addEventListener("pause",function(){
			        backgroundTime = Math.round(new Date().getTime()/1000);
			    }, false );
			    // 监听从后台切换回前台事件
			    document.addEventListener("resume",function(){
			        var nowTime = Math.round(new Date().getTime()/1000);
			        // 如果程序退出到后台时间超过20秒，则重新要求输入手势密码
			        if (backgroundTime != 0) {
			            if (nowTime - backgroundTime > 20) {
			            //	plus.runtime.restart();
			                //跳转到登陆页面
//			               closeMenu() ;
//			               plus.webview.getLaunchWebview().show();
			            }
			        }
			    }, false );
			    var mainPage = plus.webview.getWebviewById('main') ;
				if(mainPage){
					mui.fire(mainPage,'tips:set',{id:'mui-icon-home',count: 10});
				}
				
				mui.later(function() {
					xhz.syncClient();
				}, 1000);
				
			});
			var isInTransition = false;
			/**
			 * 关闭加载画面
			 */
			function closeWaiting(){
				waiting&&waiting.close();
				waiting=null;
			}
			
			/**
			 * 修改标题
			 */
			function setTitle(e){
				if(e.detail.title){
					if("home" != e.detail.title){
						document.getElementById('search').style.display='none' ;
					}else{
						document.getElementById('search').style.display='block' ;
					}
					document.getElementById('mui-title').innerHTML = titles[e.detail.title] ;
				}
				if(e.detail.back){
					document.getElementById('left-nav').style.display='block' ;
					document.getElementById('icon-bars').style.display='none' ;
				}else{
					document.getElementById('icon-bars').style.display='block' ;
					document.getElementById('left-nav').style.display='none' ;
				}
				
			}
			
			var page = mui.preload({
				url: 'login.html',
				id: 'login',
				show:{
					aniShow:'none'
				},
				waiting:{
					autoShow:false
				}
			});
			
			//首页返回键处理
			//处理逻辑：1秒内，连续两次按返回键，则退出应用；
			var first = null;
			mui.back = function() {
				//首次按键，提示‘再按一次退出应用’
				if (!first) {
					first = new Date().getTime();
					mui.toast('再按一次退出应用');
					setTimeout(function() {
						first = null;
					}, 1000);
				} else {
					if (new Date().getTime() - first < 1000) {
						plus.runtime.quit();
					}
				}
			};	
		</script>
	</body>
</html>